/// @tags: ExCRT CRT
#include <cstdio>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long LL;

constexpr int maxn = 1e5 + 3;

int n;
LL a[maxn], b[maxn];

LL exgcd(LL a, LL b, LL &x, LL &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  LL tmp = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return tmp;
}

LL qmul(LL a, LL b, LL mod) {
  LL L = a * (b >> 25) % mod * (1 << 25) % mod;
  LL R = a * (b & ((1 << 25) - 1)) % mod;
  return (L + R) % mod;
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> b[i] >> a[i];
  }
  LL M = b[1], ans = a[1], x, y, gcd, tmp;
  for (int i = 2; i <= n; ++i) {
    gcd = exgcd(M, b[i], x, y);
    tmp = (a[i] - ans) / gcd;
    x = qmul(x, tmp, b[i]);
    ans += x * M;
    M /= gcd;
    M *= b[i];
    ans = (ans % M + M) % M;
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("ExCRT.in", "r", stdin);
  freopen("ExCRT.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
